<!doctype html>


<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>continuationtestcase.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
  </script>

  <script src="static/js/doc.js">
  </script>

  <meta charset="utf8">
</head>

<body onload="prettyPrint()">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>





<div class="colmask rightmenu">
<div class="colleft">
    <div class="col1">
      <!-- Column 1 start -->

<div id="title">
       <span class="fn">continuationtestcase.js</span>
</div>

<div class="g-section g-tpl-75-25">
  <div class="g-unit g-first" id="description">
    Defines test classes for tests that can wait for conditions.

 Normal unit tests must complete their test logic within a single function
 execution. This is ideal for most tests, but makes it difficult to test
 routines that require real time to complete. The tests and TestCase in this
 file allow for tests that can wait until a condition is true before
 continuing execution.

 Each test has the typical three phases of execution: setUp, the test itself,
 and tearDown. During each phase, the test function may add wait conditions,
 which result in new test steps being added for that phase. All steps in a
 given phase must complete before moving on to the next phase. An error in
 any phase will stop that test and report the error to the test runner.

 This class should not be used where adequate mocks exist. Time-based routines
 should use the MockClock, which runs much faster and provides equivalent
 results. Continuation tests should be used for testing code that depends on
 browser behaviors that are difficult to mock. For example, testing code that
 relies on Iframe load events, event or layout code that requires a setTimeout
 to become valid, and other browser-dependent native object interactions for
 which mocks are insufficient.

 Sample usage:

 <pre class="lang-js">
 var testCase = new goog.testing.ContinuationTestCase();
 testCase.autoDiscoverTests();

 if (typeof G_testRunner != &#39;undefined&#39;) {
 G_testRunner.initialize(testCase);
 }

 function testWaiting() {
 var someVar = true;
 waitForTimeout(function() {
 assertTrue(someVar)
 }, 500);
 }

 function testWaitForEvent() {
 var et = goog.events.EventTarget();
 waitForEvent(et, &#39;test&#39;, function() {
 // Test step runs after the event fires.
 })
 et.dispatchEvent(et, &#39;test&#39;);
 }

 function testWaitForCondition() {
 var counter = 0;

 waitForCondition(function() {
 // This function is evaluated periodically until it returns true, or it
 // times out.
 return ++counter &gt;= 3;
 }, function() {
 // This test step is run once the condition becomes true.
 assertEquals(3, counter);
 });
 }
 </pre>
  </div>
  

        <div class="g-unit" id="useful-links">
          <div class="title">Useful links</div>
          <ol>
            <li><a href="closure_goog_testing_continuationtestcase.js.source.html"><span class='source-code-link'>Source Code</span></a></li>
          </ol>
        </div>
</div>

<h2 class="g-first">File Location</h2>
  <div class="g-section g-tpl-20-80">
    <div class="g-unit g-first">
      <div class="g-c-cell code-label">testing/continuationtestcase.js</div>
    </div>
  </div>
<hr/>


  <h2>Classes</h2>
 <div class="fn-constructor">
        <a href="class_goog_testing_ContinuationTestCase.html">
          goog.testing.ContinuationTestCase</a><br/>
        <div class="class-details">Constructs a test case that supports tests with continuations. Test functions
may issue &quot;wait&quot; commands that suspend the test temporarily and continue once
the wait condition is met.</div>
 </div>
 <div class="fn-constructor">
        <a href="class_goog_testing_ContinuationTestCase_Test.html">
          goog.testing.ContinuationTestCase.Test</a><br/>
        <div class="class-details">Creates a continuation test case, which consists of multiple test steps that
occur in several phases.

The steps are distributed between setUp, test, and tearDown phases. During
the execution of each step, 0 or more steps may be added to the current
phase. Once all steps in a phase have completed, the next phase will be
executed.

If any errors occur (such as an assertion failure), the setUp and Test phases
will be cancelled immediately. The tearDown phase will always start, but may
be cancelled as well if it raises an error.</div>
 </div>
 <div class="fn-constructor">
        <a href="class_goog_testing_ContinuationTestCase_Step.html">
          goog.testing.ContinuationTestCase.Step</a><br/>
        <div class="class-details">Constructs a single step in a larger continuation test. Each step is similar
to a typical TestCase test, except it may wait for an event or timeout to
occur before running the test function.</div>
 </div>
      
<br/>

  <div class="legend">
        <span class="key publickey"></span><span>Public</span>
        <span class="key protectedkey"></span><span>Protected</span>
        <span class="key privatekey"></span><span>Private</span>
  </div>


  <h2>Global Functions</h2>





<div class="section">
  <table class="horiz-rule">


     <tr class="even entry private">
       <td class="access"></td>






  <td>
    <a name="goog.testing.ContinuationTestCase.Step.protectedClearTimeout_"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.testing.ContinuationTestCase.Step.</span><span class="entryName">protectedClearTimeout_<span class="args">()</span>
        </span>
      </div>


     <div class="entryOverview">
       A saved reference to window.clearTimeout so that MockClock or other overrides
don&#39;t affect continuation timeouts.
     </div>

   
  </td>


  <td class="view-code">
     <a href="closure_goog_testing_continuationtestcase.js.source.html#line632">code &raquo;</a>
  </td>
     </tr>


     <tr class="odd entry private">
       <td class="access"></td>






  <td>
    <a name="goog.testing.ContinuationTestCase.Step.protectedSetTimeout_"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.testing.ContinuationTestCase.Step.</span><span class="entryName">protectedSetTimeout_<span class="args">()</span>
        </span>
      </div>


     <div class="entryOverview">
       A saved reference to window.setTimeout so that MockClock or other overrides
don&#39;t affect continuation timeouts.
     </div>

   
  </td>


  <td class="view-code">
     <a href="closure_goog_testing_continuationtestcase.js.source.html#line642">code &raquo;</a>
  </td>
     </tr>


  </table>
</div>



  <h2>Global Properties</h2>





<div class="section">
  <table class="horiz-rule">


     <tr class="even entry public">
       <td class="access"></td>





  <a name="goog.testing.ContinuationTestCase.MAX_TIMEOUT"></a>

  <td>


     <div class="arg">
        <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.testing.ContinuationTestCase.</span><span class="entryName">MAX_TIMEOUT</span>
        : <div class="fullType"><span class="type"><a href="http://www.google.com/url?sa=D&q=https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Number">number</a></span></div>
     </div>


     <div class="entryOverview">
       The default maximum time to wait for a single test step in milliseconds.
     </div>

  </td>


  <td class="view-code">
     <a href="closure_goog_testing_continuationtestcase.js.source.html#line117">Code &raquo;</a>
  </td>
     </tr>


     <tr class="odd entry private">
       <td class="access"></td>





  <a name="goog.testing.ContinuationTestCase.locked_"></a>

  <td>


     <div class="arg">
        <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.testing.ContinuationTestCase.</span><span class="entryName">locked_</span>
        : <div class="fullType"><span class="type"><a href="http://www.google.com/url?sa=D&q=https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Boolean">boolean</a></span></div>
     </div>


     <div class="entryOverview">
       Lock used to prevent multiple test steps from running recursively.
     </div>

  </td>


  <td class="view-code">
     <a href="closure_goog_testing_continuationtestcase.js.source.html#line125">Code &raquo;</a>
  </td>
     </tr>


  </table>
</div>



      <!-- Column 1 end -->
    </div>

        <div class="col2">
          <!-- Column 2 start -->
          <div class="col2-c">
            <h2 id="ref-head">Directory testing</h2>
            <div id="localView"></div>
          </div>

          <div class="col2-c">
            <h2 id="ref-head">File Reference</h2>
            <div id="sideFileIndex" rootPath="closure/goog" current="testing/continuationtestcase.js"></div>
          </div>
          <!-- Column 2 end -->
        </div>
</div>
</div>

</body>
</html>
